package com.xf.system.common.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xf.system.common.mapper.RoleMenuMapper;
import com.xf.system.common.model.RoleMenu;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xiefengf
 */
@Slf4j
@Service
public class RoleMenuService extends ServiceImpl<RoleMenuMapper, RoleMenu> {

    @Resource
    private RoleMenuMapper roleMenuMapper;

    /**
     * 删除角色与菜单关联
     * @param roleId 角色id
     * @return 执行结果
     */
    public Boolean deleteRoleMenuByRid(Long roleId) {
        LambdaQueryWrapper<RoleMenu> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RoleMenu::getRoleId,roleId);
        return remove(wrapper);
    }

    /**
     * 删除角色与菜单关联
     * @param roleIdList 角色id集合
     * @return 执行结果
     */
    public Boolean deleteRoleMenuByRidList(List<Long> roleIdList) {
        LambdaQueryWrapper<RoleMenu> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(RoleMenu::getRoleId,roleIdList);
        return remove(wrapper);
    }

    /**
     * 根据菜单id,查询对应的所有角色id
     *
     * @param menuId 菜单主键id
     * @return 角色Id主键集合
     */
    public List<Long> selectRoleIdByMenuId(Long menuId) {
        return roleMenuMapper.selectRoleIdByMenuId(menuId);
    }

    /**
     * 根据角色id,查询对应的所有菜单id
     *
     * @param roleId 角色主键id
     * @return 菜单Id主键集合
     */
    public List<Long> selectMenuIdByRoleId(Long roleId) {
        return roleMenuMapper.selectMenuIdByRoleId(roleId);
    }

}
